cmake_minimum_required (VERSION 2.8)
project (loadcomsol)

include (src/CMakeLists.txt)

set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules")
find_package (Tecplot REQUIRED)
message (STATUS "TECPLOT_INSTALL_DIR is ${TECPLOT_INSTALL_DIR}")

find_package (Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

if (WIN32)
    add_definitions (-DNOMINMAX) # Prevents macros from stomping on std::min/std::max
endif ()

if (UNIX)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
    add_definitions(-DLINUX)
    if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
        add_definitions(-DLINUX64)
    endif ()
endif ()

# Set warning level to 4 (the highest) on Windows
if (WIN32)
      set (CMAKE_CXX_WARNING_LEVEL 4)
      if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
            string (REGEX REPLACE "/W[0-4]" "/W4"
                    CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
      else ()
            set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
      endif ()
endif ()

add_library (${PROJECT_NAME}
    SHARED
    ${HEADER_FILES}
    ${SOURCE_FILES}
)

target_link_libraries (${PROJECT_NAME}
    ${TECPLOT_LIBS}
)

include_directories(
    "${TECPLOT_INSTALL_DIR}/include"
)

if (MSVC)
    # Set up a default .user file that contains the debugging setup
    set (SYSTEM_NAME $ENV{USERDOMAIN})
    set (USER_NAME $ENV{USERNAME})

    # Only do this if one doesn't already exist
    set (USER_FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.vcproj.${SYSTEM_NAME}.${USER_NAME}.user)
    if (NOT EXISTS "${USER_FILE}")
        message (STATUS "Creating ${USER_FILE} with default debug settings")
        # These are the configuration variables
        if (CMAKE_GENERATOR MATCHES "Win64")
            set (USERFILE_PLATFORM "x64")
        else ()
            set (USERFILE_PLATFORM "Win32")
        endif ()
        find_program (USERFILE_DEBUG_COMMAND tec360.exe
                      HINTS "${TECPLOT_INSTALL_DIR}"
                      PATH_SUFFIXES bin
                      NO_DEFAULT_PATH)

        configure_file (cmake/User2005.in ${USER_FILE})
    endif ()
endif ()
